package com.nativetalk.service.three.teacher.update;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.teacher.TdNtTeacherMinAmount;
import com.nativetalk.bean.teacher.TdNtTeacherResult;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.common.util.MemcachedUtils;
import com.nativetalk.dao.TdNtTeacherDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Created by lizhun on 16/6/27.
 */
@Service
public class ThreeTeacherUpdateServiceImpl implements  ThreeTeacherUpdateService{
    private static Logger logger = Logger.getLogger(ThreeTeacherUpdateServiceImpl.class);
    @Resource
    private TdNtTeacherDao tdNtTeacherDao;
    @Override
    public RetInfo updateTeacherMinAmount(TdNtTeacherMinAmount tdNtTeacherMinAmount,TdNtTeacherResult tdNtTeacherResult) {
        String logInfo = this.getClass().getName() + ":updateTeacherMinAmount:";
        // 类路径+方法名
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            if (tdNtTeacherMinAmount.getMin_amount().compareTo(new BigDecimal(0)) > 0) {
                tdNtTeacherDao.updateTdNtTeacherMinAmount(tdNtTeacherMinAmount);
                tdNtTeacherResult.setMin_amount(tdNtTeacherMinAmount.getMin_amount());
                MemcachedUtils.replace(tdNtTeacherResult.getToken(), tdNtTeacherResult, 20 * 24 * 60 * 60);
                retInfo.setMark(ValidationMessages.getValue("MARKYES"));
                retInfo.setTip("更新成功");
            } else {
                retInfo.setMark(ValidationMessages.getValue("MARKNO"));
                retInfo.setTip("You must enter more than 0");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo updateTeacherPay(TdNtTeacherResult tdNtTeacherResult) {
        String logInfo = this.getClass().getName() + ":updateTeacherPay:";
        // 类路径+方法名
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            tdNtTeacherDao.updateTeacherPay(tdNtTeacherResult);
            MemcachedUtils.replace(tdNtTeacherResult.getToken(), tdNtTeacherResult, 20 * 24 * 60 * 60);
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("更新成功");
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }


}
